package com.lzy.huijinjiazu.mvp.ui.dialog;

import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.flyco.dialog.widget.base.BottomBaseDialog;
import com.jess.arms.utils.ArmsUtils;
import com.lzy.huijinjiazu.R;
import com.lzy.huijinjiazu.mvp.model.entity.PayMode;
import com.lzy.huijinjiazu.mvp.ui.activity.PaymentSuccessActivity;
import com.lzy.huijinjiazu.mvp.ui.adapter.PaymentAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by long on 2018/1/16.
 */

public class PaymentDialog extends BottomBaseDialog<PaymentDialog> {

    TextView mTvPayAmount;
    RecyclerView mRvList;
    private PaymentAdapter mAdapter;
    TextView btnToPay;
    ImageView ivClose;

    public PaymentDialog(Context context) {
        super(context);
    }

    @Override
    public View onCreateView() {
        View view = LayoutInflater.from(mContext).inflate(R.layout.dialog_payment, null, false);
        initView(view);
        return view;
    }

    private void initView(View view) {
        mTvPayAmount = view.findViewById(R.id.tv_pay_amount);
        btnToPay = view.findViewById(R.id.btn_to_pay);
        ivClose = view.findViewById(R.id.iv_close);
        mRvList = view.findViewById(R.id.rv_list);
    }

    @Override
    public void setUiBeforShow() {
        mTvPayAmount.setText(Html.fromHtml(ArmsUtils.getString(mContext, R.string.shopping_cart_money, "2000", "200")));
        ArmsUtils.configRecyclerView(mRvList, new LinearLayoutManager(mContext));
        mAdapter = new PaymentAdapter();
        mRvList.setAdapter(mAdapter);
        List<PayMode> data = new ArrayList<>();
        data.add(new PayMode("余额支付", R.mipmap.ic_balance_pay, true));
        data.add(new PayMode("微信支付", R.mipmap.ic_wx_pay, false));
        data.add(new PayMode("支付宝支付", R.mipmap.ic_alipay_pay, false));
        mAdapter.setNewData(data);
        btnToPay.setOnClickListener(view -> {
            ArmsUtils.startActivity(PaymentSuccessActivity.class);
        });
        ivClose.setOnClickListener(view -> {
            dismiss();
        });
    }
}
